#ifndef QUDPSERVER_H
#define QUDPSERVER_H

#include <QObject>
#include <QtNetwork>

#include "qtNetwork_global.h"
// 监听端口
#define COMM_ENTRANCE_UDP_PORT 10118

NETWORKSERVICE_BEGIN_NAMESPACE

using namespace std;
class QTNETWORK_EXPORT QUdpServer : public QObject
{
    Q_OBJECT
public:
    explicit QUdpServer(QObject *parent = nullptr);

signals:

    // 收到数据
    void recvData(QHostAddress addr, quint16 port, QByteArray data);

public slots:

    // 数据可读
    void readDataSlots();

    // 启动
    bool start(quint16 port);

    // 发送数据
    bool sendDataToIp(const string &ip, const string &data);

private:

    // 创建QUdpSocket对象
    QUdpSocket udpSocket;
};
NETWORKSERVICE_END_NAMESPACE

#endif // QUDPSERVER_H
